<!DOCTYPE html>
<butml lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        body{
            height: 2000px;
        }
        *{margin: 0;padding: 0}
        .nav{
            opacity: 0;
            width: 100%;
            height: 50px;line-height: 50px;text-align: center;
            background: #00bcd4;position: fixed;
        }
    </style>
</head>
<body>
    <div class="nav">
        导航
    </div>
    <!-- 当我的窗口距离顶部达到200px，我就让nav完全显示 -->
    <script>
        $(window).scroll(function(){
            // 获取滚动条距离顶部的距离
            var scrollTop = $(window).scrollTop();
            // console.log(screenTop)
            var opacity= screenTop/200;
            // console.log(opacity)
            if(opacity>1){
                opacity=1
            }
            $(".nav").css({opacity:opacity})
        })
    </script>
</body>
</butml>